package com.taocore.top.title.action;

import java.sql.Connection;
import java.sql.SQLException;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;

import javax.naming.NamingException;

import org.apache.struts2.convention.annotation.Result;
import org.apache.struts2.convention.annotation.Results;

import com.taocore.top.title.db.DBUtils;
import com.taocore.top.title.db.Dao;
import com.taocore.top.title.domain.WeeklyKeyword;

@Results({
	  @Result(name="success", location="admin-keywords.jsp")
})
public class SearchAction extends ActionBase{

	static Logger _log = Logger.getLogger(SearchAction.class.getName());
	
	private String coreWord;
	private List<WeeklyKeyword> keywords;
	
	public String execute()
	{
		_log.info("coreWord: " + coreWord);
		Connection conn = null;
		try {
			conn = DBUtils.getConnection();
			keywords = Dao.INSTANCE.getWeeklyKeywordsByCoreWord(coreWord, 50, 0, conn);
		} catch (NamingException e) {
			_log.log(Level.SEVERE, "", e);
		} catch (SQLException e) {
			_log.log(Level.SEVERE, "", e);
		}
		finally
		{
			DBUtils.close(conn, null, null);
		}
		return SUCCESS;
	}

	public void setCoreWord(String coreWord) {
		this.coreWord = coreWord;
	}

	public String getCoreWord() {
		return coreWord;
	}

	public List<WeeklyKeyword> getKeywords() {
		return keywords;
	}
}
